
            
class TrouserController {
    def index = { redirect(action:list,params:params) }

    def list = {
        [ trouserList: Trouser.list( params ) ]
    }

    def show = {
        [ trouser : Trouser.get( params.id ) ]
    }

    def delete = {
        def trouser = Trouser.get( params.id )
        if(trouser) {
            trouser.delete()
            flash.message = "Trouser ${params.id} deleted."
            redirect(action:list)
        }
        else {
            flash.message = "Trouser not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def trouser = Trouser.get( params.id )

        if(!trouser) {
                flash.message = "Trouser not found with id ${params.id}"
                redirect(action:list)
        }
        else {
            return [ trouser : trouser ]
        }
    }

    def update = {
        def trouser = Trouser.get( params.id )
        if(trouser) {
             trouser.properties = params
            if(trouser.save()) {
                redirect(action:show,id:trouser.id)
            }
            else {
                render(view:'edit',model:[trouser:trouser])
            }
        }
        else {
            flash.message = "Trouser not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def trouser = new Trouser()
        trouser.properties = params
        return ['trouser':trouser]
    }

    def save = {
        def trouser = new Trouser()
        trouser.properties = params
        if(trouser.save()) {
            redirect(action:show,id:trouser.id)
        }
        else {
            render(view:'create',model:[trouser:trouser])
        }
    }

}